
import java.util.LinkedHashMap;
import java.util.Properties;

import com.alibaba.fastjson.JSON;
import org.apache.kafka.clients.producer.KafkaProducer;
import org.apache.kafka.clients.producer.Producer;
import org.apache.kafka.clients.producer.ProducerRecord;

public class MsgProducer {

    public static void main(String[] args) {
        Properties props = new Properties();
        props.put("bootstrap.servers", "192.168.43.19:9092");
        props.put("acks", "all");
        props.put("retries", 0);
        props.put("batch.size", 16384);//16KB
        props.put("linger.ms", 1);
        props.put("buffer.memory", 33554432);//32MB
        props.put("key.serializer", "org.apache.kafka.common.serialization.StringSerializer");
        props.put("value.serializer", "JsonSerialize");

        Producer<String, Object> producer = new KafkaProducer<>(props);

        LinkedHashMap _tmp = new LinkedHashMap();
        _tmp.put("unit_id","10-10-24-12:192_168_57_18-cpu");
        _tmp.put("kpi_id","PM-00-01-002-02");
        _tmp.put("data_time","2019-09-10 16:49:56");
        _tmp.put("interval_time","300000");
        _tmp.put("kpi_value","17.88");
        _tmp.put("postion","n/r");

//        ArrayList list = new ArrayList();
//        list.add(_tmp);
        Object obj =  JSON.toJSON(_tmp);
        producer.send(new ProducerRecord<String, Object>("2019gnyw", "2019 9999", obj));
        producer.close();

    }
}